package com.spa.domain.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.domain.entity.Feedback;
import com.spa.infrastructure.mapper.FeedbackMapperStruct;
import com.spa.infrastructure.repository.condition.FeedbackCondition;
import com.spa.infrastructure.repository.po.FeedbackPO;
import com.spa.infrastructure.repository.service.FeedbackRepositoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 反馈表(Feedback)服务实现类
 *
 * @author lig
 * @since 2024-01-11 10:14:59
 */
@Service
public class FeedbackService {

    @Resource
    private FeedbackRepositoryService feedbackRepositoryService;

    public boolean addInfo(FeedbackPO po){
        return feedbackRepositoryService.save(po);
    }

    public Page<Feedback> pageListInfo(FeedbackCondition condition) {

        Page<FeedbackPO> page = feedbackRepositoryService.pageListInfo(condition);
        Page<Feedback> pageEntity = FeedbackMapperStruct.INSTANCE.po2Entity4Page(page);

        buildBaseFeedback(pageEntity.getRecords());

        return pageEntity;

    }

    public List<Feedback> listInfo(FeedbackCondition condition) {

        List<FeedbackPO> list = feedbackRepositoryService.listInfo(condition);
        List<Feedback> listEntity = FeedbackMapperStruct.INSTANCE.po2Entity4List(list);

        buildBaseFeedback(listEntity);

        return listEntity;

    }

    /**
     * 构造基础信息
     *
     * @author: lig
     * @date: 2024/1/16
     */
    private void buildBaseFeedback(List<Feedback> list){
        list.stream().forEach(a ->{
            a.setImgList(Feedback.imgsTotagList(a.getImgs()));
        });

    }

}
